# !/usr/bin/env python
# -*- coding:utf-8 -*-
# @FileName : p6.py
# @Time     : 2024/5/7 23:30
# @Author   : Robot-Zsj
"""
description:

数据单元的变化替换

https://fcqian.blog.csdn.net/article/details/134939544?spm=1001.2014.3001.5502

i:
1,2<A>00

o:
1,2100
"""

import re

regexp = re.compile(r"(<.*?>)")

cells = input().split(",")


def changeCell(index):
    matchers = regexp.findall(cells[index])

    for reference in matchers:
        if len(reference) != 3:
            return False
        reference_cellNum = reference[1]
        self_cellNum = chr(65 + index)

        if reference_cellNum < 'A' or reference_cellNum > 'Z' or reference_cellNum == self_cellNum:
            return False

        reference_index = ord(reference_cellNum) - 65

        if reference_index >= len(cells):
            return False

        if not changeCell(reference_index):
            return False

        cells[index] = cells[index].replace(reference, cells[reference_index])

    return True


def getResult():
    if len(cells) > 26:
        return "-1"

    for i in range(len(cells)):
        if not changeCell(i):
            return "-1"

        if len(cells[i]) > 100:
            return "-1"

        if not re.match(r"^[a-zA-Z0-9]+$", cells[i]):
            return "-1"

    return ",".join(cells)


print(getResult())
